﻿#include <stdio.h>
#include <time.h>
#include "async_task.h"
// 编译方法：gcc -o async_task async_task.c  priority_queue.c main.c -lpthread

void test_func(void *user_data)
{
    time_t timep;
    time(&timep); /*获取time_t类型当前时间*/
    printf("%s  -> %s come\n\n", ctime(&timep), (char *)user_data);

    //printf("%s coming, time = %ld\n\n", (char *)user_data, (int64_t)(get_now_time()/1000));
}
int main()
{
    char str1[] = "Once Timer task";
    char str2[] = "Loop Timer task";
    char str3[] = "Once of task";
    task_handle_t task_handle1;
    task_handle_t task_handle2;
    task_handle_t task_handle3;
    thread_handle_t  async_thread = aysnc_task_init(50);
/*
    task_handle1 = async_task_add(async_thread,
                                  kOnceTimerTask,
                                  2000,
                                  (void*)str1,
                                  test_func);*/
	//*
    task_handle2 = async_task_add(async_thread,
                                  kLoopTimerTask,
                                  2000,
                                  (void*)str2,
                                  test_func);//*/
     /*                            
    task_handle3 = async_task_add(async_thread,
                                  kOnceOffTask,
                                  0,
                                  (void*)str3,
                                  test_func); */

    //while (1)
    {
		/*
        sleep(7);
        async_task_delete(async_thread, task_handle3);
        sleep(7);
        async_task_delete(async_thread, task_handle2);
        sleep(2);
        async_task_delete(async_thread, task_handle1);
        task_handle2 = async_task_add(async_thread,
                                      kLoopTimerTask,
                                      1000,
                                      (void*)str2,
                                      test_func);
                                      */
        sleep(10);
    }
    aysnc_task_deinit(async_thread);

    printf("\n---------- main finish ----------- \n");

    return 0;
}
